const { body } = require('express-validator')
const validate = require('../middleware/validator')
const Column = require('../models/index/Column')

exports.createColumn = validate([
  body('name')
    .notEmpty()
    .withMessage('专栏标题不能为空')
    .custom(async (name) => {
      const column = await Column.findOne({
        where: {
          name
        }
      })
      if (column) {
        return Promise.reject('专栏已存在')
      }
    })
])
